package org.example.demo.config;

import com.alibaba.druid.support.json.JSONUtils;
import org.example.demo.util.JWTUtils;
import org.example.demo.util.ReturnMap;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.PrintWriter;

public class TokenInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("Authorization");
        String requestUri = request.getRequestURI();
        if (token == null || token.isEmpty() || !JWTUtils.checkToken(token)) {
            response.setStatus(401);
            return false;
        }
        return true;
    }

}
